package com.example.rbac.config;

import org.apache.ibatis.binding.MapperProxy;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.FactoryBean;

import java.lang.reflect.Proxy;

//@MapperScan
public class MapperFactory<T> implements FactoryBean<T>{
    private Class<T> mapperInterface;
    private Handle mapperProxy;
    public MapperFactory(Class<T> mapperInterface, Handle mapperProxy) {
        this.mapperInterface = mapperInterface;
        this.mapperProxy = mapperProxy;
    }


    public T getObject() {
        return (T) Proxy.newProxyInstance(this.mapperInterface.getClassLoader(), new Class[]{this.mapperInterface}, mapperProxy);
    }

    @Override
    public Class<?> getObjectType() {
        return this.mapperInterface;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}
